<template>
  <section class="login-bg">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" 
    @keyup.native.enter="handleSubmit"
    label-width="0px" class="login-container">
      <h3 class="title">天南山文化后台管理系统</h3>
      <el-form-item prop="account">
        <el-input type="text" autofocus v-model="ruleForm.account" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-checkbox v-model="checked" class="remember">
        同意使用协议
      </el-checkbox>
      <span @click="show = true" class="agreement">点击查看</span>
      <el-form-item>
        <el-button type="primary" 
          style="width:100%;" 
          @click.native.prevent="handleSubmit" 
          :loading="logining">登录
        </el-button>
      </el-form-item>
      <div class="other-way">
        <hr>
        <span class="info">请使用高版本浏览器</span>
    </div>
    </el-form>
    <div class="account-about ">
      <span>Copyright&nbsp;&nbsp;©&nbsp;2017&nbsp;yuethink.com&nbsp;&nbsp;</span>
      <a href="http://www.yuethink.com" target="_blank">技术支持-贵州越想互联科技有限公司</a>
      <a href="http://www.miitbeian.gov.cn/" target="_blank">黔ICP备17008981号</a>
      <span>Version 1.0</span>
    </div>
    <el-dialog
      title="使用协议"
      :visible.sync="show"
      width="50%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false">
      <span>{{agreement}}</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="agree(false)">不同意</el-button>
        <el-button type="primary" @click="agree(true)">同 意</el-button>
      </span>
    </el-dialog>
  </section>
</template>
<script>
  export default {
    data () {
      return {
        logining: false,
        show: false,
        agreement: '',
        ruleForm: {
          account: '',
          password: ''
        },
        rules: {
          account: [
            {required: true, message: '请输入账号', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请输入密码', trigger: 'blur'}
          ]
        },
        checked: false
      }
    },
    mounted () {
      this.$http.get('/configs/byKey/teacher_agreement').then((response) => {
        this.agreement = response.data
      })
    },
    methods: {
      agree (agree) {
        this.show = false
        this.checked = agree
      },
      handleSubmit (ev) {
        if (!this.checked) {
          this.show = true
          this.$message.error('同意使用协议才能使用本系统')
          return false
        }
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            this.logining = true
            this.$store.dispatch('login', this.ruleForm).then((response) => {
              this.logining = false
              this.$router.push({ path: '/' })
            }).catch(() => {
              this.logining = false
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .login-bg {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #ccc;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: url(./images/bg.jpg) center center / cover no-repeat fixed;
    &:before {
      content: '';
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      background: rgba(0, 0, 0, .5);
    }
    .login-container {
      z-index: 100;
      -webkit-border-radius: 5px;
      border-radius: 5px;
      -moz-border-radius: 5px;
      background-clip: padding-box;
      width: 350px;
      padding: 35px 35px 15px 35px;
      background: #fff;
      border: 1px solid #eaeaea;
      box-shadow: 0 0 25px #cac6c6;
      .title {
        margin: 0 auto 40px auto;
        text-align: center;
        color: #505458;
      }
      .remember {
        margin: 0 0 35px 0;
      }
    }
    .account-about {
      position: absolute;
      font-size: 14px;
      left: 30px;
      bottom: 25px;
      a, span {
        color: #666;
        text-decoration: none;
        margin-right: 15px;
      }
    }
    .other-way {
    position: relative;
    hr {
      height: 1px;
      margin: 30px 0 20px;
      border: 0;
      background-color: #e4e7ed;
      display: block;
    }
    .info {
      font-size: 14px;
      line-height: 1;
      position: absolute;
      top: -6px;
      left: 50%;
      padding: 0 10px;
      transform: translate(-50%,0);
      color: #9ba3af;
      background-color: #fff;
    }
  }
  }
  .agreement {
    font-size: 12px;
    color: #999;
    text-decoration: underline;
    cursor: pointer;
  }
</style>